package com.tencent.wxcloudrun.common;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * ClassName: Utils
 * Package: com.tencent.wxcloudrun.common
 * Description:
 *
 * @Date: 2023/1/31 7:39 PM
 * @Author: wht
 */
public class Utils {
    public static String getNewToken() {
        String nowTime = String.valueOf(System.currentTimeMillis());
        String random = String.valueOf(Math.random());
        String token = nowTime + random;
        return token;
    }

    public static String encryptPassword(String password) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(password.getBytes());
        byte[] bytes = md.digest();
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }
}
